package com.neuedu.security.security;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.security.entity.SysUser;
import com.neuedu.security.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public class SecurityUserDetailsService implements UserDetailsService {

    @Autowired
    ISysUserService userService;



    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {


        QueryWrapper<SysUser> queryWarpper = new QueryWrapper<>();
        queryWarpper.eq("user_name",username);
        SysUser user = null;

        user =   userService.getOne(queryWarpper);
        if(user == null){
            throw  new UsernameNotFoundException("username== "+username);
        }


        return  new SecurityUserDetails(user);
    }


}
